package com.jason.redCherry.common;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * Created by Jason on 2016/8/19.
 */
public class ConfigValue {

    /********************* 常量配置 *********************/
    public static String IMAGEURL = "imageUrl";
    public static String COMPONENT_URL = "component_url";
    public static String INNER_PLAT_CGI_WEB_URL = "inner_plat_cgi_web_url";
    public static String INNER_PLAT_CGI_MOCK_URL = "inner_plat_cgi_mock_url";
    public static String ACT_SAVE_PATH = "act_save_path";
    public static String ACT_PREVIEW_PATH = "act_preview_path";

    /********************* 常量配置 *********************/

    private static Properties prop;

    static {
        init();
    }

    private static void init() {

        String name = "config.properties";

        InputStream in = Object.class.getResourceAsStream(name);
        try {
            prop.load(in);
        } catch (IOException e) {
            e.printStackTrace();
        }

        ConfigValue.setProp(prop);

        initConst();
    }

    private static void initConst() {

        IMAGEURL = getProperties(IMAGEURL);

        COMPONENT_URL = getProperties(COMPONENT_URL);

        INNER_PLAT_CGI_WEB_URL = getProperties(INNER_PLAT_CGI_WEB_URL);

        INNER_PLAT_CGI_MOCK_URL = getProperties(INNER_PLAT_CGI_MOCK_URL);

        ACT_SAVE_PATH = getProperties(ACT_SAVE_PATH);

        ACT_PREVIEW_PATH = getProperties(ACT_PREVIEW_PATH);

    }


    public static String getProperties(String key) {

        return getProp().getProperty(key);
    }

    public static String getProperties(String key, String defaultValue) {

        return getProp().getProperty(key, defaultValue);
    }


    public static Properties getProp() {
        return prop;
    }

    public static void setProp(Properties prop) {
        ConfigValue.prop = prop;
    }
}
